//Sweepstake implementation

#include "sweeps.h"
#include <iostream>
using namespace std;

sweeps::sweeps(){
               sync sync_obj;
               control control_obj;
               winner = "";
               numEntries = 0;
               sweepsline.set_sync(&sync_obj);
}
                 

sweeps::sweeps(sync *sync_object,  control *control_object){
               sync_obj = sync_object;
               control_obj = control_object;
               winner = "";
               numEntries = 0;
               sweepsline.set_sync(sync_object);
}

void sweeps::add2queue(Customer_Obj customer){
                               sweepsline.enqueue(customer);
}
                               
Customer_Obj sweeps::register_dequeue(){
             Customer_Obj customer;
             customer = sweepsline.dequeue();
             entries[numEntries] = customer.getFirstName() + " " + customer.getLastName();
             cout << "Entry Name: " << entries[numEntries++] << endl;
             return(customer);
}

Customer_Obj sweeps::peek(){
             return(sweepsline.peek());
}

string sweeps::draw_winner(){
       //cout << numEntries << endl;
       //cout << "And the winner is... "; 
       srand(time(NULL)+numEntries);
       int a = rand() % numEntries;
       winner = entries[a];
       return(winner);
}

int sweeps::sweeps_size(){
    return(numEntries);
}

int sweeps::line_size(){
    return(sweepsline.getCurrentSize());
}

void sweeps::show_stats(){
     Time maxWaitT(sweepsline.getMaxWait());
     Time avgWaitT(sweepsline.getAvgWait());
     cout << "--Sweepstakes--" << endl;
     cout << sweepsline.getNumProcessed() << " Customers Processed" << endl;
     cout << "Maximum Size of Line: " << sweepsline.getMaxSize() << endl;
     cout << "Maximum Wait Time: "; maxWaitT.dispTime(); cout << endl;
     cout << "Average Wait Time: "; avgWaitT.dispTime(); cout << endl;
}
